<?php
/*
 * Created on Feb 1, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 /*
  * functionality is 
  * show green-tick for valid vat id, red cross for invalid. do not check each-time page is loaded 
	rather show stored value(true/false)
	
	provide a button where admin can check again.
	
	provide another button which will automatically send a peice of mail(use a mail template) to the 
	user/customer to verify his/her vat id by reply mail.
  */
  
/**
 * Admin order manager vat id check.
 * 
 * Admin Menu: Admin Orders -> Orders.
 * @package modules\eb_EUVAT\admin
 */
class eb_EUVAT_vatcheck extends eb_EUVAT_vatcheck_parent{
	
	//check which template to return
	private $_bMailStatus = false;
	
	 /**
     * Executes parent method parent::render(), creates object
     * and passes it's data to Smarty engine. Returns name of template
     * file "eb_EUVAT_vatcheck.tpl".
     *
     * @return string
     */
    public function render(){
    	
    	parent::render();
    	if($this->_bMailStatus)return "eb_EUVAT_vatmail.tpl";
    	else return "eb_EUVAT_vatcheck.tpl";
    }
	
	/*
     * set vat status value
     * 
     * @param none
     * 
     * @return void
     * 
     */
	public function eb_EUVAT_validate_vatuid(){
		
		//$oVatService = oxNew("eb_EUVAT_vatuid_utility");
		//$this->_aViewData["vatresponse"] = $oVatService->eb_EUVAT_call_vatcheck();
		$bstatus = oxConfig::getParameter( "datavalid");
		$svatid = oxConfig::getParameter( "vatid");
		$this->_aViewData["valid_vatuid"] =  $bstatus;
		$this->_aViewData["vatuid"] = $svatid ;
		if($bstatus){
			oxSession::setVar( "vatstatus",$svatid);
			//echo oxSession::getVar( "vatstatus");
		}
		
	}
	
	/*
     * send mail to user for their vat id validation provided user id is not empty
     * 
     * @param none
     * 
     * @return void
     * 
     */
	public function eb_EUVAT_sendmail_vatuid(){
		$sUid = null;
		$ret = false;
		$this->_bMailStatus = true;
		$sUid = oxConfig::getParameter( "userid");
		$sVatid = oxConfig::getParameter( "vatid");
		if($sUid){
			
			$oUser = oxNew( "oxUser" );
    	
	    	/*$sUViewName = $oUser->getViewName();
	        $sQ = "select $sUViewName.oxid  from  $sUViewName ";
	        if ( $sActiveSnippet = $oUser->getSqlActiveSnippet() ) {
	            $sQ .= " where $sActiveSnippet ";
	        }
	       echo $sQ .= " and oxshopid='".oxSession::getVar( "actshop" )."' and oxusername='".$sUid."'";
	
	    	$oDB = oxDb::getDb();
    		$rs  = $oDB->GetOne($sQ);*/
    	
			$oUser->load($sUid);
			$subject = oxLang::getInstance()->translateString("EB_EUVAT_VATUID_MAILTEXT6");
			$oMail = oxNew("oxemail");
			$ret = $oMail->eb_EUVAT_sendVATEmailToUser($oUser,$subject,$sVatid ); 
		}
		
		if($ret){
			$ret = oxLang::getInstance()->translateString("EB_EUVAT_VATUID_MAILTEXT4");
		}else{
			
			$ret = oxLang::getInstance()->translateString("EB_EUVAT_VATUID_MAILTEXT5");
		}
		$this->_aViewData["msgstatus"] = $ret;
		
	}
}
?>
